// TestEbml.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "./ebml/EbmlIO.h"
#include "./ebml/ColasoftIO.h"

using namespace ebml;

int _tmain(int argc, _TCHAR* argv[])
{
	if (true)
	{
		ColasoftIO ofile(_T("c:\\test.kax"), IO_MODE_WRITE);
		EbmlMaster* ebml_head = ToMaster(ofile.CreateElement("EBMLHead"));

		EbmlUInteger* version = ToUInteger(ebml_head->GetChild("EVersion"));
		version->SetData(9);

		EbmlString* doctype = ToString(ebml_head->GetChild("EDocType"));
		doctype->SetData("colasoft");

		uint32 written_len = 0;
		ebml_head->Render(written_len);

		ofile.Close();
	}

	if (false)
	{
		ColasoftIO ifile(_T("c:\\test.kax"), IO_MODE_READ);
		EbmlElement* first_elmt = ifile.FindFirstElement();
		if (first_elmt->GetName() == "EBMLHead")
		{
			EbmlMaster* ebml_head = dynamic_cast<EbmlMaster*>(first_elmt);
			
			EbmlString* doctype = dynamic_cast<EbmlString*>(ebml_head->FindChild("EDocType"));
			string dt;
			if (doctype)
			{
				doctype->GetData(dt);
			}

			EbmlBinary* docdata = dynamic_cast<EbmlBinary*>(ebml_head->FindChild("EDocData"));
			void* data;
			uint32 len;
			if (docdata)
			{
				docdata->GetData(data, len);
			}

			EbmlUInteger* version = dynamic_cast<EbmlUInteger*>(ebml_head->FindChild("EVersion"));
			uint64 vs;
			if (version)
			{
				version->GetData(vs);
			}

			printf("xxx\n");
		}

		ifile.Close();
	}

	printf("ddd\n");
// 	unsigned char buf[8];
// 	memset(buf, 0, 8);
// 	buf[0] = 0x12;
// 	buf[1] = 0xA1;
// 	uint64 v = *(uint64*)buf;
// 	v <<= 8;
// 	v <<= 8;
// 	printf("%i64\n", v);
// 	EbmlIO io;
// 	EbmlInt* eb = new EbmlInt(io);
// 	eb->SetValue(0xffffffffffffffff);
// 	int64 cc = 0;
// 	cc = *eb;
// 	eb->SetValue(22);
// 	cc = *eb;
// 	delete eb;
// 
// 	EbmlString es(io);
// 	es.SetValue("hzg");
// 	string myname = es;
	return 0;
}

